
<?php
	/* 
	 CONNECT-DB.PHP
	 Allows PHP to connect to your database
	*/
	
	// Database Variables (edit with your own server information)
	 
	define('HOSTNAME', 'localhost');
	define('USERNAME', 'root');
	define('PASSWORD', '');
	define('DATABASE', 'demo_daotao');
	
	//Connect Database
	$connection = mysql_connect(HOSTNAME, USERNAME, PASSWORD) or die ("Could not connect to server ... \n" . mysql_error ());
	
	mysql_query("SET character_set_results=utf8", $connection);
	mb_language('uni');
	mb_internal_encoding('UTF-8');
	
	//Seclect Database
	mysql_select_db(DATABASE, $connection) or die ("Could not connect to server ... \n" . mysql_error ());
	
	mysql_query("SET NAMES 'utf8'",$connection);
	 
	 
	//Create Tables if not exists
	mysql_query('Create table if not exists donvi ( 
												`id` INT( 8 ) NOT NULL AUTO_INCREMENT ,
												`maDonvi` VARCHAR( 64 ) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL ,
												`tenKhoa` VARCHAR( 64 ) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL ,
												`tenBomon` VARCHAR( 64 ) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL ,
												PRIMARY KEY (  `maDonvi` ) ,UNIQUE (`id`)
												) ENGINE = MYISAM ;'
				) or die("Don't create Table donvi");
	 
	mysql_query('Create table if not exists `nganh` (
												`id` INT( 8 ) NOT NULL AUTO_INCREMENT ,
												`maNganh` VARCHAR( 64 ) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL ,
												`tenViettat` VARCHAR( 64 ) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL ,
												`tenDaydu` VARCHAR( 64 ) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL ,
												`maDonvi` VARCHAR( 64 ) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL ,
												PRIMARY KEY (  `maNganh` ) ,
												UNIQUE (`id`),
												FOREIGN KEY (`maDonvi`) REFERENCES donvi(`maDonvi`)
												) ENGINE = MYISAM ;'
				) or die("Don't create Table nganh");
				
	mysql_query('Create table if not exists `khoadaotao` (
												`id` INT( 8 ) NOT NULL AUTO_INCREMENT ,
												`maKhoaDT` VARCHAR( 64 ) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL ,
												`maNganh` VARCHAR( 64 ) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL ,
												`tenKhoaDT` VARCHAR( 64 ) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL ,
												`soNamDaotao` VARCHAR( 64 ) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL ,
												PRIMARY KEY (  `maKhoaDT` ) ,
												UNIQUE (`id`),
												FOREIGN KEY (`maNganh`) REFERENCES nganh(`maNganh`)
												) ENGINE = MYISAM ;'
				) or die("Don't create Table khoadaotao");
				
?>